package com.newbingo.service;

import com.newbingo.dao.imple.IAgentDao;
import com.newbingo.dao.imple.IGameDao;
import com.newbingo.dao.imple.IGameRebateDao;
import com.newbingo.dto.GameRebateDto;
import com.newbingo.dto.imple.IGameRebateDto;
import com.newbingo.entity.Agent;
import com.newbingo.entity.Game;
import com.newbingo.entity.GameRebate;
import com.newbingo.service.imple.IGameRebateService;
import com.newbingo.util.Pager;

public class GameRebateService implements IGameRebateService {
	private IGameRebateDao gameRebateDao = null;
	private IGameRebateDto gameRebateDto = null;
	private IAgentDao agentDao = null;
	private IGameDao gameDao = null;

	public IAgentDao getAgentDao() {
		return agentDao;
	}

	public void setAgentDao(IAgentDao agentDao) {
		this.agentDao = agentDao;
	}
	
	public GameRebate findLastestRebateByAgent(Integer agentId){
		return gameRebateDao.findLastestRebateByAgent(agentId);
	}

	/*
	 * 删除(non-Javadoc)
	 * @see com.newbingo.service.imple.IGameRebateService#delete(com.newbingo.entity.GameRebate)
	 */
	public void delete(GameRebate rebate) {
		gameRebateDao.delete(rebate);
	}

	/*
	 * 根据ID查询、返回DTO对象(non-Javadoc)
	 * @see com.newbingo.service.imple.IGameRebateService#findById(java.lang.Integer)
	 */
	public GameRebateDto findById(Integer Id) {
		return gameRebateDto.findById(Id);
	}

	/*
	 * 分页查询(non-Javadoc)
	 * @see com.newbingo.service.imple.IGameRebateService#findRebate(int, int, java.lang.Integer, java.lang.String)
	 */
	public Pager findRebate(int start, int limit, Integer agentId,
			String gameName) {
		return gameRebateDto.findRebate(start, limit, agentId, gameName);
	}

	/*
	 * 修改(non-Javadoc)
	 * @see com.newbingo.service.imple.IGameRebateService#merger(com.newbingo.entity.GameRebate)
	 */
	public GameRebate merger(GameRebate rebate) {
		GameRebate gameRebate = gameRebateDao.findById(rebate.getId());
		gameRebate.setAmount(rebate.getAmount());
		gameRebate.setRebate(rebate.getRebate());
		gameRebate.setStartTime(rebate.getStartTime());
		gameRebate.setEndTime(rebate.getEndTime());
		return gameRebateDao.merger(gameRebate);

	}

	/*
	 * 保存(non-Javadoc)
	 * @see com.newbingo.service.imple.IGameRebateService#save(com.newbingo.entity.GameRebate)
	 */
	public void save(GameRebate rebate) {
		Agent agent = agentDao.findById(rebate.getAgent().getUno());
		Game game = gameDao.findById(rebate.getGame().getGameno());
		rebate.setAgent(agent);
		gameRebateDao.save(rebate);
	}

	public IGameRebateDao getGameRebateDao() {
		return gameRebateDao;
	}

	public void setGameRebateDao(IGameRebateDao gameRebateDao) {
		this.gameRebateDao = gameRebateDao;
	}

	public IGameRebateDto getGameRebateDto() {
		return gameRebateDto;
	}

	public void setGameRebateDto(IGameRebateDto gameRebateDto) {
		this.gameRebateDto = gameRebateDto;
	}

	public IGameDao getGameDao() {
		return gameDao;
	}

	public void setGameDao(IGameDao gameDao) {
		this.gameDao = gameDao;
	}

}
